Skip to content

[clang] Add scoped enum support to StreamingDiagnostic #138089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2025

Conversation

Endilll
Copy link
Contributor

@Endilll Endilll commented May 1, 2025

This patch adds templated operator<< for diagnostics that pass scoped enums, saving people from llvm::to_underlying() clutter on the side of emitting the diagnostic. This eliminates 80 out of 220 usages of llvm::to_underlying() in Clang.

I also backported std::is_scoped_enum_v from C++23.

@Endilll Endilll added clang:frontend Language frontend issues, e.g. anything involving "Sema" code-quality labels May 1, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category llvm:adt labels May 1, 2025
@llvmbot
Copy link
Member

llvmbot commented May 1, 2025

@llvm/pr-subscribers-llvm-adt

@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)

Changes

This patch adds templated operator&lt;&lt; for diagnostics that pass scoped enums, saving people from llvm::to_underlying() clutter on the side of emitting the diagnostic. This eliminates 80 out of 220 usages of llvm::to_underlying() in Clang.

I also backported std::is_scoped_enum_v from C++23.


Patch is 40.33 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/138089.diff

25 Files Affected:

  • (modified) clang/include/clang/Basic/Diagnostic.h (+16)
  • (modified) clang/include/clang/Sema/Sema.h (-11)
  • (modified) clang/lib/AST/ODRDiagsEmitter.cpp (+2-4)
  • (modified) clang/lib/Parse/ParseDecl.cpp (+1-1)
  • (modified) clang/lib/Parse/ParseDeclCXX.cpp (+1-1)
  • (modified) clang/lib/Parse/ParsePragma.cpp (+2-1)
  • (modified) clang/lib/Parse/Parser.cpp (+1-1)
  • (modified) clang/lib/Sema/SemaAccess.cpp (+3-6)
  • (modified) clang/lib/Sema/SemaCUDA.cpp (+7-10)
  • (modified) clang/lib/Sema/SemaChecking.cpp (+3-5)
  • (modified) clang/lib/Sema/SemaDecl.cpp (+12-15)
  • (modified) clang/lib/Sema/SemaDeclAttr.cpp (+1-1)
  • (modified) clang/lib/Sema/SemaDeclCXX.cpp (+28-34)
  • (modified) clang/lib/Sema/SemaDeclObjC.cpp (+1-1)
  • (modified) clang/lib/Sema/SemaExpr.cpp (+7-11)
  • (modified) clang/lib/Sema/SemaExprCXX.cpp (+1-1)
  • (modified) clang/lib/Sema/SemaInit.cpp (+1-2)
  • (modified) clang/lib/Sema/SemaOverload.cpp (+2-3)
  • (modified) clang/lib/Sema/SemaStmt.cpp (+1-1)
  • (modified) clang/lib/Sema/SemaTemplate.cpp (+3-5)
  • (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+2-3)
  • (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+2-2)
  • (modified) clang/lib/Sema/SemaType.cpp (+1-1)
  • (modified) clang/lib/Sema/TreeTransform.h (+3-5)
  • (modified) llvm/include/llvm/ADT/STLForwardCompat.h (+4)
diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h
index 19524856a9bb3..92ab61b95a7c6 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -1429,6 +1429,22 @@ operator<<(const StreamingDiagnostic &DB, T *DC) {
   return DB;
 }
 
+// Convert scope enums to their underlying type, so that we don't have
+// clutter the emitting code with `llvm::to_underlying()`.
+// We also need to disable implicit conversion for the first argument,
+// because classes that derive from StreamingDiagnostic define their own
+// templated operator<< that accept a wide variety of types, leading
+// to ambiguity.
+template <typename T, typename U>
+inline std::enable_if_t<
+    std::is_same_v<std::remove_const_t<T>, StreamingDiagnostic> &&
+        llvm::is_scoped_enum_v<std::remove_reference_t<U>>,
+    const StreamingDiagnostic &>
+operator<<(const T &DB, U &&SE) {
+  DB << llvm::to_underlying(SE);
+  return DB;
+}
+
 inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
                                              SourceLocation L) {
   DB.AddSourceRange(CharSourceRange::getTokenRange(L));
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 28313f45b1228..003583f84cf97 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -220,11 +220,6 @@ enum class AssignmentAction {
   Casting,
   Passing_CFAudited
 };
-inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
-                                             const AssignmentAction &AA) {
-  DB << llvm::to_underlying(AA);
-  return DB;
-}
 
 namespace threadSafety {
 class BeforeSet;
@@ -15471,12 +15466,6 @@ void Sema::PragmaStack<Sema::AlignPackInfo>::Act(SourceLocation PragmaLocation,
                                                  llvm::StringRef StackSlotLabel,
                                                  AlignPackInfo Value);
 
-inline const StreamingDiagnostic &
-operator<<(const StreamingDiagnostic &DB, Sema::StringEvaluationContext Ctx) {
-  DB << llvm::to_underlying(Ctx);
-  return DB;
-}
-
 } // end namespace clang
 
 #endif
diff --git a/clang/lib/AST/ODRDiagsEmitter.cpp b/clang/lib/AST/ODRDiagsEmitter.cpp
index 37f0f68c92355..74f3881ed3c96 100644
--- a/clang/lib/AST/ODRDiagsEmitter.cpp
+++ b/clang/lib/AST/ODRDiagsEmitter.cpp
@@ -461,10 +461,8 @@ bool ODRDiagsEmitter::diagnoseSubMismatchObjCMethod(
   }
   if (FirstMethod->getImplementationControl() !=
       SecondMethod->getImplementationControl()) {
-    DiagError(ControlLevel)
-        << llvm::to_underlying(FirstMethod->getImplementationControl());
-    DiagNote(ControlLevel) << llvm::to_underlying(
-        SecondMethod->getImplementationControl());
+    DiagError(ControlLevel) << FirstMethod->getImplementationControl();
+    DiagNote(ControlLevel) << SecondMethod->getImplementationControl();
     return true;
   }
   if (FirstMethod->isThisDeclarationADesignatedInitializer() !=
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 9dd9d9c637592..cd6464678c4b5 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -2578,7 +2578,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
     if (TemplateInfo.Kind != ParsedTemplateKind::NonTemplate &&
         D.isFirstDeclarator()) {
       Diag(CommaLoc, diag::err_multiple_template_declarators)
-          << llvm::to_underlying(TemplateInfo.Kind);
+          << TemplateInfo.Kind;
     }
 
     // Parse the next declarator.
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 8dfc0fa53dd88..7e0a8af07a3be 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -3472,7 +3472,7 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration(
     if (TemplateInfo.Kind != ParsedTemplateKind::NonTemplate &&
         DeclaratorInfo.isFirstDeclarator()) {
       Diag(CommaLoc, diag::err_multiple_template_declarators)
-          << llvm::to_underlying(TemplateInfo.Kind);
+          << TemplateInfo.Kind;
     }
 
     // Parse the next declarator.
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 026a35639abdf..9f9e4bb92af8c 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -2341,7 +2341,8 @@ void PragmaClangSectionHandler::HandlePragma(Preprocessor &PP,
     SourceLocation PragmaLocation = Tok.getLocation();
     PP.Lex(Tok); // eat ['bss'|'data'|'rodata'|'text']
     if (Tok.isNot(tok::equal)) {
-      PP.Diag(Tok.getLocation(), diag::err_pragma_clang_section_expected_equal) << llvm::to_underlying(SecKind);
+      PP.Diag(Tok.getLocation(), diag::err_pragma_clang_section_expected_equal)
+          << SecKind;
       return;
     }
 
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 120d44238ea35..ec87317897200 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -226,7 +226,7 @@ void Parser::ConsumeExtraSemi(ExtraSemiKind Kind, DeclSpec::TST TST) {
 
   if (Kind != ExtraSemiKind::AfterMemberFunctionDefinition || HadMultipleSemis)
     Diag(StartLoc, diag::ext_extra_semi)
-        << llvm::to_underlying(Kind)
+        << Kind
         << DeclSpec::getSpecifierName(
                TST, Actions.getASTContext().getPrintingPolicy())
         << FixItHint::CreateRemoval(SourceRange(StartLoc, EndLoc));
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index b77cbdb234f1f..890df09157aa0 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -1670,24 +1670,21 @@ Sema::AccessResult Sema::CheckConstructorAccess(SourceLocation UseLoc,
   case InitializedEntity::EK_Base:
     PD = PDiag(diag::err_access_base_ctor);
     PD << Entity.isInheritedVirtualBase()
-       << Entity.getBaseSpecifier()->getType()
-       << llvm::to_underlying(getSpecialMember(Constructor));
+       << Entity.getBaseSpecifier()->getType() << getSpecialMember(Constructor);
     break;
 
   case InitializedEntity::EK_Member:
   case InitializedEntity::EK_ParenAggInitMember: {
     const FieldDecl *Field = cast<FieldDecl>(Entity.getDecl());
     PD = PDiag(diag::err_access_field_ctor);
-    PD << Field->getType()
-       << llvm::to_underlying(getSpecialMember(Constructor));
+    PD << Field->getType() << getSpecialMember(Constructor);
     break;
   }
 
   case InitializedEntity::EK_LambdaCapture: {
     StringRef VarName = Entity.getCapturedVarName();
     PD = PDiag(diag::err_access_lambda_capture);
-    PD << VarName << Entity.getType()
-       << llvm::to_underlying(getSpecialMember(Constructor));
+    PD << VarName << Entity.getType() << getSpecialMember(Constructor);
     break;
   }
 
diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp
index 0a8c24f8be537..45595068ea938 100644
--- a/clang/lib/Sema/SemaCUDA.cpp
+++ b/clang/lib/Sema/SemaCUDA.cpp
@@ -450,8 +450,7 @@ bool SemaCUDA::inferTargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl,
         if (Diagnose) {
           Diag(ClassDecl->getLocation(),
                diag::note_implicit_member_target_infer_collision)
-              << (unsigned)CSM << llvm::to_underlying(*InferredTarget)
-              << llvm::to_underlying(BaseMethodTarget);
+              << (unsigned)CSM << *InferredTarget << BaseMethodTarget;
         }
         MemberDecl->addAttr(
             CUDAInvalidTargetAttr::CreateImplicit(getASTContext()));
@@ -496,8 +495,7 @@ bool SemaCUDA::inferTargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl,
         if (Diagnose) {
           Diag(ClassDecl->getLocation(),
                diag::note_implicit_member_target_infer_collision)
-              << (unsigned)CSM << llvm::to_underlying(*InferredTarget)
-              << llvm::to_underlying(FieldMethodTarget);
+              << (unsigned)CSM << *InferredTarget << FieldMethodTarget;
         }
         MemberDecl->addAttr(
             CUDAInvalidTargetAttr::CreateImplicit(getASTContext()));
@@ -713,7 +711,7 @@ void SemaCUDA::checkAllowedInitializer(VarDecl *VD) {
       if (InitFnTarget != CUDAFunctionTarget::Host &&
           InitFnTarget != CUDAFunctionTarget::HostDevice) {
         Diag(VD->getLocation(), diag::err_ref_bad_target_global_initializer)
-            << llvm::to_underlying(InitFnTarget) << InitFn;
+            << InitFnTarget << InitFn;
         Diag(InitFn->getLocation(), diag::note_previous_decl) << InitFn;
         VD->setInvalidDecl();
       }
@@ -952,8 +950,8 @@ bool SemaCUDA::CheckCall(SourceLocation Loc, FunctionDecl *Callee) {
 
   SemaDiagnosticBuilder(DiagKind, Loc, diag::err_ref_bad_target, Caller,
                         SemaRef)
-      << llvm::to_underlying(IdentifyTarget(Callee)) << /*function*/ 0 << Callee
-      << llvm::to_underlying(IdentifyTarget(Caller));
+      << IdentifyTarget(Callee) << /*function*/ 0 << Callee
+      << IdentifyTarget(Caller);
   if (!Callee->getBuiltinID())
     SemaDiagnosticBuilder(DiagKind, Callee->getLocation(),
                           diag::note_previous_decl, Caller, SemaRef)
@@ -1049,8 +1047,7 @@ void SemaCUDA::checkTargetOverload(FunctionDecl *NewFD,
           (NewTarget == CUDAFunctionTarget::Global) ||
           (OldTarget == CUDAFunctionTarget::Global)) {
         Diag(NewFD->getLocation(), diag::err_cuda_ovl_target)
-            << llvm::to_underlying(NewTarget) << NewFD->getDeclName()
-            << llvm::to_underlying(OldTarget) << OldFD;
+            << NewTarget << NewFD->getDeclName() << OldTarget << OldFD;
         Diag(OldFD->getLocation(), diag::note_previous_declaration);
         NewFD->setInvalidDecl();
         break;
@@ -1060,7 +1057,7 @@ void SemaCUDA::checkTargetOverload(FunctionDecl *NewFD,
           (NewTarget == CUDAFunctionTarget::Device &&
            OldTarget == CUDAFunctionTarget::Host)) {
         Diag(NewFD->getLocation(), diag::warn_offload_incompatible_redeclare)
-            << llvm::to_underlying(NewTarget) << llvm::to_underlying(OldTarget);
+            << NewTarget << OldTarget;
         Diag(OldFD->getLocation(), diag::note_previous_declaration);
       }
     }
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2d648898cdea1..92ec2fec519b1 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -8339,8 +8339,7 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
       } else {
         EmitFormatDiagnostic(
             S.PDiag(diag::warn_non_pod_vararg_with_format_string)
-                << S.getLangOpts().CPlusPlus11 << ExprTy
-                << llvm::to_underlying(CallType)
+                << S.getLangOpts().CPlusPlus11 << ExprTy << CallType
                 << AT.getRepresentativeTypeName(S.Context) << CSR
                 << E->getSourceRange(),
             E->getBeginLoc(), /*IsStringLocation*/ false, CSR);
@@ -8354,8 +8353,7 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
       else if (ExprTy->isObjCObjectType())
         EmitFormatDiagnostic(
             S.PDiag(diag::err_cannot_pass_objc_interface_to_vararg_format)
-                << S.getLangOpts().CPlusPlus11 << ExprTy
-                << llvm::to_underlying(CallType)
+                << S.getLangOpts().CPlusPlus11 << ExprTy << CallType
                 << AT.getRepresentativeTypeName(S.Context) << CSR
                 << E->getSourceRange(),
             E->getBeginLoc(), /*IsStringLocation*/ false, CSR);
@@ -8363,7 +8361,7 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
         // FIXME: If this is an initializer list, suggest removing the braces
         // or inserting a cast to the target type.
         S.Diag(E->getBeginLoc(), diag::err_cannot_pass_to_vararg_format)
-            << isa<InitListExpr>(E) << ExprTy << llvm::to_underlying(CallType)
+            << isa<InitListExpr>(E) << ExprTy << CallType
             << AT.getRepresentativeTypeName(S.Context) << E->getSourceRange();
       break;
     }
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 56396cddf57b8..092cfcf48fc1d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -4034,13 +4034,13 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S,
         } else {
           Diag(NewMethod->getLocation(),
                diag::err_definition_of_implicitly_declared_member)
-              << New << llvm::to_underlying(getSpecialMember(OldMethod));
+              << New << getSpecialMember(OldMethod);
           return true;
         }
       } else if (OldMethod->getFirstDecl()->isExplicitlyDefaulted() && !isFriend) {
         Diag(NewMethod->getLocation(),
              diag::err_definition_of_explicitly_defaulted_member)
-            << llvm::to_underlying(getSpecialMember(OldMethod));
+            << getSpecialMember(OldMethod);
         return true;
       }
     }
@@ -5246,7 +5246,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
   if (DS.isModulePrivateSpecified() &&
       Tag && Tag->getDeclContext()->isFunctionOrMethod())
     Diag(DS.getModulePrivateSpecLoc(), diag::err_module_private_local_class)
-        << llvm::to_underlying(Tag->getTagKind())
+        << Tag->getTagKind()
         << FixItHint::CreateRemoval(DS.getModulePrivateSpecLoc());
 
   ActOnDocumentableDecl(TagD);
@@ -7719,15 +7719,14 @@ NamedDecl *Sema::ActOnVariableDeclarator(
             // data members.
             Diag(D.getIdentifierLoc(),
                  diag::err_static_data_member_not_allowed_in_local_class)
-                << Name << RD->getDeclName()
-                << llvm::to_underlying(RD->getTagKind());
+                << Name << RD->getDeclName() << RD->getTagKind();
           } else if (AnonStruct) {
             // C++ [class.static.data]p4: Unnamed classes and classes contained
             // directly or indirectly within unnamed classes shall not contain
             // static data members.
             Diag(D.getIdentifierLoc(),
                  diag::err_static_data_member_not_allowed_in_anon_struct)
-                << Name << llvm::to_underlying(AnonStruct->getTagKind());
+                << Name << AnonStruct->getTagKind();
             Invalid = true;
           } else if (RD->isUnion()) {
             // C++98 [class.union]p1: If a union contains a static data member,
@@ -17658,7 +17657,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
 
       // A tag 'foo::bar' must already exist.
       Diag(NameLoc, diag::err_not_tag_in_scope)
-          << llvm::to_underlying(Kind) << Name << DC << SS.getRange();
+          << Kind << Name << DC << SS.getRange();
       Name = nullptr;
       Invalid = true;
       goto CreateNewDecl;
@@ -18116,7 +18115,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
           !Previous.isForRedeclaration()) {
         NonTagKind NTK = getNonTagTypeDeclKind(PrevDecl, Kind);
         Diag(NameLoc, diag::err_tag_reference_non_tag)
-            << PrevDecl << NTK << llvm::to_underlying(Kind);
+            << PrevDecl << NTK << Kind;
         Diag(PrevDecl->getLocation(), diag::note_declared_at);
         Invalid = true;
 
@@ -19015,8 +19014,7 @@ bool Sema::CheckNontrivialField(FieldDecl *FD) {
             getLangOpts().CPlusPlus11
                 ? diag::warn_cxx98_compat_nontrivial_union_or_anon_struct_member
                 : diag::err_illegal_union_or_anon_struct_member)
-            << FD->getParent()->isUnion() << FD->getDeclName()
-            << llvm::to_underlying(member);
+            << FD->getParent()->isUnion() << FD->getDeclName() << member;
         DiagnoseNontrivial(RDecl, member);
         return !getLangOpts().CPlusPlus11;
       }
@@ -19356,8 +19354,7 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
         unsigned DiagID = 0;
         if (!Record->isUnion() && !IsLastField) {
           Diag(FD->getLocation(), diag::err_flexible_array_not_at_end)
-              << FD->getDeclName() << FD->getType()
-              << llvm::to_underlying(Record->getTagKind());
+              << FD->getDeclName() << FD->getType() << Record->getTagKind();
           Diag((*(i + 1))->getLocation(), diag::note_next_field_declaration);
           FD->setInvalidDecl();
           EnclosingDecl->setInvalidDecl();
@@ -19373,7 +19370,7 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
 
         if (DiagID)
           Diag(FD->getLocation(), DiagID)
-              << FD->getDeclName() << llvm::to_underlying(Record->getTagKind());
+              << FD->getDeclName() << Record->getTagKind();
         // While the layout of types that contain virtual bases is not specified
         // by the C++ standard, both the Itanium and Microsoft C++ ABIs place
         // virtual bases after the derived members.  This would make a flexible
@@ -19381,10 +19378,10 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
         // of the type.
         if (CXXRecord && CXXRecord->getNumVBases() != 0)
           Diag(FD->getLocation(), diag::err_flexible_array_virtual_base)
-              << FD->getDeclName() << llvm::to_underlying(Record->getTagKind());
+              << FD->getDeclName() << Record->getTagKind();
         if (!getLangOpts().C99)
           Diag(FD->getLocation(), diag::ext_c99_flexible_array_member)
-              << FD->getDeclName() << llvm::to_underlying(Record->getTagKind());
+              << FD->getDeclName() << Record->getTagKind();
 
         // If the element type has a non-trivial destructor, we would not
         // implicitly destroy the elements, so disallow it for now.
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index ab66ae860f86b..9d6a1c77f5aaf 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5058,7 +5058,7 @@ static void handleSharedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   }
   if (S.getLangOpts().CUDA && VD->hasLocalStorage() &&
       S.CUDA().DiagIfHostCode(AL.getLoc(), diag::err_cuda_host_shared)
-          << llvm::to_underlying(S.CUDA().CurrentTarget()))
+          << S.CUDA().CurrentTarget())
     return;
   D->addAttr(::new (S.Context) CUDASharedAttr(S.Context, AL));
 }
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 645a0887c0f19..a7e68682d5320 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -647,7 +647,7 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old,
       ParmVarDecl *NewParam = New->getParamDecl(New->getMinRequiredArguments());
       assert(NewParam->hasDefaultArg());
       Diag(NewParam->getLocation(), diag::err_default_arg_makes_ctor_special)
-          << NewParam->getDefaultArgRange() << llvm::to_underlying(NewSM);
+          << NewParam->getDefaultArgRange() << NewSM;
       Diag(Old->getLocation(), diag::note_previous_declaration);
     }
   }
@@ -6978,7 +6978,7 @@ void Sema::CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record) {
           (F->getType().isConstQualified() && F->getType()->isScalarType())) {
         if (!Complained) {
           Diag(Record->getLocation(), diag::warn_no_constructor_for_refconst)
-              << llvm::to_underlying(Record->getTagKind()) << Record;
+              << Record->getTagKind() << Record;
           Complained = true;
         }
 
@@ -7774,14 +7774,14 @@ bool Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD,
     // default argument is classified as a default constructor, and assignment
     // operations and destructors can't have default arguments.
     Diag(MD->getLocation(), diag::err_defaulted_special_member_params)
-        << llvm::to_underlying(CSM) << MD->getSourceRange();
+        << CSM << MD->getSourceRange();
     HadError = true;
   } else if (MD->isVariadic()) {
     if (DeleteOnTypeMismatch)
       ShouldDeleteForTypeMismatch = true;
     else {
       Diag(MD->getLocation(), diag::err_defaulted_special_member_variadic)
-          << llvm::to_underlying(CSM) << MD->getSourceRange();
+          << CSM << MD->getSourceRange();
       HadError = true;
     }
   }
@@ -7868,7 +7868,7 @@ bool Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD,
       else {
         Diag...
[truncated]

std::is_same_v<std::remove_const_t<T>, StreamingDiagnostic> &&
llvm::is_scoped_enum_v<std::remove_reference_t<U>>,
const StreamingDiagnostic &>
operator<<(const T &DB, U &&SE) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why operator<<(const StreamingDiagnostic &DB, U &&SE) would not work - if there are ambiguities in the derived classes, can we fix those instead? you have examples?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I do what you suggest, this pre-existing operator<<

template <typename T> const DiagnosticBuilder &operator<<(const T &V) const {
assert(isActive() && "Clients must not add to cleared diagnostic!");
const StreamingDiagnostic &DB = *this;
DB << V;
return *this;
}

causes the following ambiguity:

/home/user/endill/llvm-project/clang/lib/Parse/Parser.cpp:229:9: error: use of overloaded operator '<<' is ambiguous (with operand types 'DiagnosticBuilder' and 'ExtraSemiKind')
  228 |     Diag(StartLoc, diag::ext_extra_semi)
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  229 |         << Kind
      |         ^  ~~~~
/home/user/endill/llvm-project/clang/include/clang/Basic/Diagnostic.h:1297:50: note: candidate function [with T = clang::ExtraSemiKind]
 1297 |   template <typename T> const DiagnosticBuilder &operator<<(const T &V) const {
      |                                                  ^
/home/user/endill/llvm-project/clang/include/clang/Basic/Diagnostic.h:1443:1: note: candidate function [with U = clang::ExtraSemiKind &]
 1443 | operator<<(const StreamingDiagnostic &DB, U &&SE) {
      | ^

This patch is far from my first attempt to implement this, but the first one that didn't run into one of those ambiguity errors. Overload set of operator<< for diagnostics is somewhat convoluted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given only two classes seem to inherit from StreamingDiagnostic, maybe we can add an overload to each of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that. First you add an overload, then you need to modify the existing overload to not be a viable candidate when a scoped enum is passed. The new overload also have to copy any checks or asserts that the old one does, otherwise they will be skipped. I wasn't able to make it work, and it would be more complicated than the approach here anyway.

Copy link
Contributor

@cor3ntin cor3ntin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we would use constraints for that, when we switch to c++20.
In the meantime it is an improvement !

@Endilll
Copy link
Contributor Author

Endilll commented May 1, 2025

Ideally we would use constraints for that, when we switch to c++20.

I'd love to, yeah

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Endilll Endilll merged commit 001cc34 into llvm:main May 1, 2025
16 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented May 1, 2025

LLVM Buildbot has detected a new failure on builder clangd-ubuntu-tsan running on clangd-ubuntu-clang while building clang,llvm at step 5 "build-clangd-clangd-index-server-clangd-indexer".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/134/builds/17904

Here is the relevant piece of the build log for the reference
Step 5 (build-clangd-clangd-index-server-clangd-indexer) failure: build (failure)
...
454.792 [1420/18/1842] Building CXX object tools/clang/lib/APINotes/CMakeFiles/obj.clangAPINotes.dir/APINotesTypes.cpp.o
455.305 [1419/18/1843] Building CXX object lib/Target/XCore/TargetInfo/CMakeFiles/LLVMXCoreInfo.dir/XCoreTargetInfo.cpp.o
455.375 [1418/18/1844] Building X86GenGlobalISel.inc...
455.387 [1417/18/1845] Linking CXX static library lib/libLLVMXCoreInfo.a
455.423 [1416/18/1846] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/CLWarnings.cpp.o
455.859 [1415/18/1847] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/ASTSourceDescriptor.cpp.o
456.604 [1414/18/1848] Building X86GenDAGISel.inc...
456.730 [1413/18/1849] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/CharInfo.cpp.o
457.079 [1412/18/1850] Building RISCVGenGlobalISel.inc...
457.708 [1411/18/1851] Building CXX object tools/clang/lib/APINotes/CMakeFiles/obj.clangAPINotes.dir/APINotesManager.cpp.o
FAILED: tools/clang/lib/APINotes/CMakeFiles/obj.clangAPINotes.dir/APINotesManager.cpp.o 
ccache /usr/bin/clang++ -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/lib/APINotes -I/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang/lib/APINotes -I/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang/include -I/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/include -I/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/include -I/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fno-omit-frame-pointer -gline-tables-only -fsanitize=thread -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT tools/clang/lib/APINotes/CMakeFiles/obj.clangAPINotes.dir/APINotesManager.cpp.o -MF tools/clang/lib/APINotes/CMakeFiles/obj.clangAPINotes.dir/APINotesManager.cpp.o.d -o tools/clang/lib/APINotes/CMakeFiles/obj.clangAPINotes.dir/APINotesManager.cpp.o -c /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang/lib/APINotes/APINotesManager.cpp
In file included from /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang/lib/APINotes/APINotesManager.cpp:9:
In file included from /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang/include/clang/APINotes/APINotesManager.h:12:
In file included from /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang/include/clang/Basic/SourceLocation.h:17:
In file included from /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang/include/clang/Basic/FileEntry.h:17:
In file included from /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang/include/clang/Basic/CustomizableOptional.h:12:
In file included from /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/llvm/include/llvm/ADT/Hashing.h:47:
In file included from /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/llvm/include/llvm/ADT/ADL.h:12:
/usr/bin/../lib/gcc/x86_64-linux-gnu/7/../../../../include/c++/7/type_traits:2242:15: error: only enumeration types have underlying types
 2242 |       typedef __underlying_type(_Tp) type;
      |               ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/7/../../../../include/c++/7/type_traits:2488:5: note: in instantiation of template class 'std::underlying_type<const clang::SourceRange>' requested here
 2488 |     using underlying_type_t = typename underlying_type<_Tp>::type;
      |     ^
/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/llvm/include/llvm/ADT/STLForwardCompat.h:76:51: note: in instantiation of template type alias 'underlying_type_t' requested here
   76 | template <typename T, typename UnderlyingT = std::underlying_type_t<T>>
      |                                                   ^
/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang/include/clang/Basic/Diagnostic.h:1441:15: note: in instantiation of default argument for 'is_scoped_enum_v<std::remove_reference_t<const SourceRange &>>' required here
 1441 |         llvm::is_scoped_enum_v<std::remove_reference_t<U>>,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang/include/clang/Basic/Diagnostic.h:1490:8: note: while substituting deduced template arguments into function template 'operator<<' [with T = StreamingDiagnostic, U = const clang::SourceRange &]
 1490 |     DB << *Opt;
      |        ^
In file included from /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang/lib/APINotes/APINotesManager.cpp:9:
In file included from /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang/include/clang/APINotes/APINotesManager.h:12:
In file included from /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang/include/clang/Basic/SourceLocation.h:17:
In file included from /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang/include/clang/Basic/FileEntry.h:17:
In file included from /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang/include/clang/Basic/CustomizableOptional.h:12:
In file included from /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/llvm/include/llvm/ADT/Hashing.h:47:
In file included from /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/llvm/include/llvm/ADT/ADL.h:12:
/usr/bin/../lib/gcc/x86_64-linux-gnu/7/../../../../include/c++/7/type_traits:2242:15: error: only enumeration types have underlying types
 2242 |       typedef __underlying_type(_Tp) type;
      |               ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/7/../../../../include/c++/7/type_traits:2488:5: note: in instantiation of template class 'std::underlying_type<const clang::CharSourceRange>' requested here
 2488 |     using underlying_type_t = typename underlying_type<_Tp>::type;
      |     ^
/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/llvm/include/llvm/ADT/STLForwardCompat.h:76:51: note: in instantiation of template type alias 'underlying_type_t' requested here
   76 | template <typename T, typename UnderlyingT = std::underlying_type_t<T>>

@llvm-ci
Copy link
Collaborator

llvm-ci commented May 1, 2025

LLVM Buildbot has detected a new failure on builder openmp-offload-sles-build-only running on rocm-worker-hw-04-sles while building clang,llvm at step 5 "compile-openmp".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/140/builds/22326

Here is the relevant piece of the build log for the reference
Step 5 (compile-openmp) failure: build (failure)
...
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/llvm/include/llvm/IR/ModuleSummaryIndex.h: In member function ‘const llvm::TypeIdSummary* llvm::ModuleSummaryIndex::getTypeIdSummary(llvm::StringRef) const’:
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/llvm/include/llvm/IR/ModuleSummaryIndex.h:1890:39: warning: unused variable ‘GUID’ [-Wunused-variable]
     for (const auto &[GUID, TypeIdPair] : make_range(TidIter))
                                       ^
225.154 [3176/32/3964] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/OperatorPrecedence.cpp.o
225.154 [3175/32/3965] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/FileEntry.cpp.o
225.314 [3174/32/3966] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/FileSystemStatCache.cpp.o
225.317 [3173/32/3967] Building CXX object tools/bugpoint/CMakeFiles/bugpoint.dir/ExtractFunction.cpp.o
225.319 [3172/32/3968] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/OffloadArch.cpp.o
225.371 [3171/32/3969] Building CXX object tools/clang/lib/APINotes/CMakeFiles/obj.clangAPINotes.dir/APINotesManager.cpp.o
FAILED: tools/clang/lib/APINotes/CMakeFiles/obj.clangAPINotes.dir/APINotesManager.cpp.o 
ccache /usr/bin/c++ -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/clang/lib/APINotes -I/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/lib/APINotes -I/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/include -Itools/clang/include -Iinclude -I/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -Wno-misleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++1z -MD -MT tools/clang/lib/APINotes/CMakeFiles/obj.clangAPINotes.dir/APINotesManager.cpp.o -MF tools/clang/lib/APINotes/CMakeFiles/obj.clangAPINotes.dir/APINotesManager.cpp.o.d -o tools/clang/lib/APINotes/CMakeFiles/obj.clangAPINotes.dir/APINotesManager.cpp.o -c /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/lib/APINotes/APINotesManager.cpp
In file included from /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/llvm/include/llvm/ADT/ADL.h:12:0,
                 from /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/llvm/include/llvm/ADT/Hashing.h:47,
                 from /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/include/clang/Basic/CustomizableOptional.h:12,
                 from /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/include/clang/Basic/FileEntry.h:17,
                 from /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/include/clang/Basic/SourceLocation.h:17,
                 from /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/include/clang/APINotes/APINotesManager.h:12,
                 from /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/lib/APINotes/APINotesManager.cpp:9:
/usr/include/c++/7/type_traits: In instantiation of ‘struct std::underlying_type<const clang::SourceRange>’:
/usr/include/c++/7/type_traits:2488:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const clang::SourceRange]’
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_To>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = clang::StreamingDiagnostic; U = const clang::SourceRange&]’
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/include/clang/Basic/Diagnostic.h:1490:12:   required from here
/usr/include/c++/7/type_traits:2242:38: error: ‘const clang::SourceRange’ is not an enumeration type
       typedef __underlying_type(_Tp) type;
                                      ^~~~
/usr/include/c++/7/type_traits: In instantiation of ‘struct std::underlying_type<const clang::CharSourceRange>’:
/usr/include/c++/7/type_traits:2488:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const clang::CharSourceRange]’
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_To>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = clang::StreamingDiagnostic; U = const clang::CharSourceRange&]’
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/include/clang/Basic/Diagnostic.h:1498:12:   required from here
/usr/include/c++/7/type_traits:2242:38: error: ‘const clang::CharSourceRange’ is not an enumeration type
/usr/include/c++/7/type_traits: In instantiation of ‘struct std::underlying_type<const clang::FixItHint>’:
/usr/include/c++/7/type_traits:2488:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const clang::FixItHint]’
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_To>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = clang::StreamingDiagnostic; U = const clang::FixItHint&]’
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/include/clang/Basic/Diagnostic.h:1505:12:   required from here
/usr/include/c++/7/type_traits:2242:38: error: ‘const clang::FixItHint’ is not an enumeration type
/usr/include/c++/7/type_traits: In instantiation of ‘struct std::underlying_type<const char [18]>’:
/usr/include/c++/7/type_traits:2488:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const char [18]]’
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_To>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = llvm::raw_fd_ostream; U = const char (&)[18]]’
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/include/clang/Basic/LangOptions.h:1194:21:   required from here
/usr/include/c++/7/type_traits:2242:38: error: ‘const char [18]’ is not an enumeration type
/usr/include/c++/7/type_traits: In instantiation of ‘struct std::underlying_type<const unsigned int>’:
/usr/include/c++/7/type_traits:2488:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const unsigned int]’
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_To>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = llvm::raw_ostream; U = const unsigned int&]’
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/include/clang/Basic/LangOptions.h:1194:45:   required from here
/usr/include/c++/7/type_traits:2242:38: error: ‘const unsigned int’ is not an enumeration type
/usr/include/c++/7/type_traits: In instantiation of ‘struct std::underlying_type<const char [24]>’:
/usr/include/c++/7/type_traits:2488:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const char [24]]’
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_To>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = llvm::raw_ostream; U = const char (&)[24]]’

@Endilll
Copy link
Contributor Author

Endilll commented May 1, 2025

Apparently, my implementation of is_scoped_enum_v is not SFINAE-able enough. I'm working on a fix.

@llvm-ci
Copy link
Collaborator

llvm-ci commented May 1, 2025

LLVM Buildbot has detected a new failure on builder clang-ppc64le-linux-test-suite running on ppc64le-clang-test-suite while building clang,llvm at step 5 "build-unified-tree".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/95/builds/12696

Here is the relevant piece of the build log for the reference
Step 5 (build-unified-tree) failure: build (failure)
...
136.777 [2373/1154/2090] Building X86GenAsmWriter1.inc...
136.810 [2372/1154/2091] Building X86GenInstrMapping.inc...
136.813 [2371/1154/2092] Building X86GenMnemonicTables.inc...
136.818 [2370/1154/2093] Building CXX object tools/llvm-readobj/CMakeFiles/llvm-readobj.dir/Win64EHDumper.cpp.o
136.822 [2369/1154/2094] Building CXX object lib/ExecutionEngine/JITLink/CMakeFiles/LLVMJITLink.dir/loongarch.cpp.o
136.826 [2368/1154/2095] Building CXX object lib/ExecutionEngine/JITLink/CMakeFiles/LLVMJITLink.dir/ppc64.cpp.o
136.839 [2367/1154/2096] Building CXX object lib/ExecutionEngine/JITLink/CMakeFiles/LLVMJITLink.dir/riscv.cpp.o
136.843 [2366/1154/2097] Building CXX object lib/ExecutionEngine/Orc/CMakeFiles/LLVMOrcJIT.dir/EPCDebugObjectRegistrar.cpp.o
136.852 [2365/1154/2098] Building CXX object tools/llvm-exegesis/lib/CMakeFiles/LLVMExegesis.dir/MCInstrDescView.cpp.o
136.862 [2364/1154/2099] Building CXX object tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/ScratchBuffer.cpp.o
FAILED: tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/ScratchBuffer.cpp.o 
ccache /usr/lib64/ccache/c++ -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/build/tools/clang/lib/Lex -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/lib/Lex -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/build/tools/clang/include -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/build/include -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -Wno-misleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/ScratchBuffer.cpp.o -MF tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/ScratchBuffer.cpp.o.d -o tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/ScratchBuffer.cpp.o -c /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/lib/Lex/ScratchBuffer.cpp
In file included from /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/llvm/include/llvm/ADT/ADL.h:12,
                 from /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/llvm/include/llvm/ADT/Hashing.h:47,
                 from /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include/clang/Basic/CustomizableOptional.h:12,
                 from /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include/clang/Basic/FileEntry.h:17,
                 from /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include/clang/Basic/SourceLocation.h:17,
                 from /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include/clang/Lex/ScratchBuffer.h:16,
                 from /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/lib/Lex/ScratchBuffer.cpp:13:
/usr/include/c++/8/type_traits: In instantiation of ‘struct std::underlying_type<const clang::SourceRange>’:
/usr/include/c++/8/type_traits:2299:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const clang::SourceRange]’
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_UniformRandomNumberGenerator>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = clang::StreamingDiagnostic; U = const clang::SourceRange&]’
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include/clang/Basic/Diagnostic.h:1490:12:   required from here
/usr/include/c++/8/type_traits:2002:38: error: ‘const clang::SourceRange’ is not an enumeration type
       typedef __underlying_type(_Tp) type;
                                      ^~~~
/usr/include/c++/8/type_traits: In instantiation of ‘struct std::underlying_type<const clang::CharSourceRange>’:
/usr/include/c++/8/type_traits:2299:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const clang::CharSourceRange]’
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_UniformRandomNumberGenerator>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = clang::StreamingDiagnostic; U = const clang::CharSourceRange&]’
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include/clang/Basic/Diagnostic.h:1498:12:   required from here
/usr/include/c++/8/type_traits:2002:38: error: ‘const clang::CharSourceRange’ is not an enumeration type
/usr/include/c++/8/type_traits: In instantiation of ‘struct std::underlying_type<const clang::FixItHint>’:
/usr/include/c++/8/type_traits:2299:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const clang::FixItHint]’
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_UniformRandomNumberGenerator>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = clang::StreamingDiagnostic; U = const clang::FixItHint&]’
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include/clang/Basic/Diagnostic.h:1505:12:   required from here
/usr/include/c++/8/type_traits:2002:38: error: ‘const clang::FixItHint’ is not an enumeration type
136.864 [2364/1153/2100] Building CXX object tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/OptionUtils.cpp.o
FAILED: tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/OptionUtils.cpp.o 
ccache /usr/lib64/ccache/c++ -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/build/tools/clang/lib/Driver -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/lib/Driver -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/build/tools/clang/include -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/build/include -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -Wno-misleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/OptionUtils.cpp.o -MF tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/OptionUtils.cpp.o.d -o tools/clang/lib/Driver/CMakeFiles/obj.clangDriver.dir/OptionUtils.cpp.o -c /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/lib/Driver/OptionUtils.cpp
In file included from /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/llvm/include/llvm/Support/type_traits.h:17,
                 from /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/llvm/include/llvm/Support/Casting.h:18,
                 from /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include/clang/Basic/LLVM.h:21,
                 from /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include/clang/Basic/DiagnosticIDs.h:18,
                 from /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include/clang/Basic/Diagnostic.h:17,
                 from /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/lib/Driver/OptionUtils.cpp:9:
/usr/include/c++/8/type_traits: In instantiation of ‘struct std::underlying_type<const clang::SourceRange>’:
/usr/include/c++/8/type_traits:2299:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const clang::SourceRange]’
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_Dp>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = clang::StreamingDiagnostic; U = const clang::SourceRange&]’
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/clang/include/clang/Basic/Diagnostic.h:1490:12:   required from here

template <typename T, typename U>
inline std::enable_if_t<
std::is_same_v<std::remove_const_t<T>, StreamingDiagnostic> &&
llvm::is_scoped_enum_v<std::remove_reference_t<U>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this to be std::remove_cvref_t?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked that const qualifier doesn't get in the way, and that's what we do in other similar cases. Happy to be proven wrong by buildbots.

@llvm-ci
Copy link
Collaborator

llvm-ci commented May 1, 2025

LLVM Buildbot has detected a new failure on builder amdgpu-offload-rhel-8-cmake-build-only running on rocm-docker-rhel-8 while building clang,llvm at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/204/builds/8048

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: '../llvm-zorg/zorg/buildbot/builders/annotated/amdgpu-offload-cmake.py --jobs=32' (failure)
...
[4113/7793] Building CXX object tools/clang/lib/APINotes/CMakeFiles/obj.clangAPINotes.dir/APINotesTypes.cpp.o
[4114/7793] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/ASTSourceDescriptor.cpp.o
[4115/7793] Building CXX object tools/mlir/lib/Tools/mlir-translate/CMakeFiles/obj.MLIRTranslateLib.dir/MlirTranslateMain.cpp.o
[4116/7793] Building CXX object tools/mlir/lib/Tools/tblgen-lsp-server/CMakeFiles/TableGenLspServerLib.dir/LSPServer.cpp.o
[4117/7793] Building CXX object tools/mlir/examples/minimal-opt/CMakeFiles/mlir-cat.dir/mlir-cat.cpp.o
[4118/7793] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/CodeGenOptions.cpp.o
[4119/7793] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/OperatorPrecedence.cpp.o
[4120/7793] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/FileEntry.cpp.o
[4121/7793] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/MakeSupport.cpp.o
[4122/7793] Building CXX object tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/DependencyDirectivesScanner.cpp.o
FAILED: tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/DependencyDirectivesScanner.cpp.o 
ccache /usr/bin/c++ -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/build/tools/clang/lib/Lex -I/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/lib/Lex -I/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include -I/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/build/tools/clang/include -I/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/build/include -I/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -Wno-misleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/DependencyDirectivesScanner.cpp.o -MF tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/DependencyDirectivesScanner.cpp.o.d -o tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/DependencyDirectivesScanner.cpp.o -c /home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/lib/Lex/DependencyDirectivesScanner.cpp
In file included from /home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/llvm/include/llvm/ADT/ADL.h:12,
                 from /home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/llvm/include/llvm/ADT/Hashing.h:47,
                 from /home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/CustomizableOptional.h:12,
                 from /home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/FileEntry.h:17,
                 from /home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/SourceLocation.h:17,
                 from /home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Lex/DependencyDirectivesScanner.h:20,
                 from /home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/lib/Lex/DependencyDirectivesScanner.cpp:17:
/usr/include/c++/8/type_traits: In instantiation of ‘struct std::underlying_type<const clang::SourceRange>’:
/usr/include/c++/8/type_traits:2299:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const clang::SourceRange]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_UniformRandomNumberGenerator>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = clang::StreamingDiagnostic; U = const clang::SourceRange&]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/Diagnostic.h:1490:12:   required from here
/usr/include/c++/8/type_traits:2002:38: error: ‘const clang::SourceRange’ is not an enumeration type
       typedef __underlying_type(_Tp) type;
                                      ^~~~
/usr/include/c++/8/type_traits: In instantiation of ‘struct std::underlying_type<const clang::CharSourceRange>’:
/usr/include/c++/8/type_traits:2299:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const clang::CharSourceRange]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_UniformRandomNumberGenerator>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = clang::StreamingDiagnostic; U = const clang::CharSourceRange&]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/Diagnostic.h:1498:12:   required from here
/usr/include/c++/8/type_traits:2002:38: error: ‘const clang::CharSourceRange’ is not an enumeration type
/usr/include/c++/8/type_traits: In instantiation of ‘struct std::underlying_type<const clang::FixItHint>’:
/usr/include/c++/8/type_traits:2299:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const clang::FixItHint]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_UniformRandomNumberGenerator>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = clang::StreamingDiagnostic; U = const clang::FixItHint&]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/Diagnostic.h:1505:12:   required from here
/usr/include/c++/8/type_traits:2002:38: error: ‘const clang::FixItHint’ is not an enumeration type
/usr/include/c++/8/type_traits: In instantiation of ‘struct std::underlying_type<const char [18]>’:
/usr/include/c++/8/type_traits:2299:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const char [18]]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_UniformRandomNumberGenerator>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = llvm::raw_fd_ostream; U = const char (&)[18]]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/LangOptions.h:1194:21:   required from here
/usr/include/c++/8/type_traits:2002:38: error: ‘const char [18]’ is not an enumeration type
/usr/include/c++/8/type_traits: In instantiation of ‘struct std::underlying_type<const unsigned int>’:
/usr/include/c++/8/type_traits:2299:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const unsigned int]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_UniformRandomNumberGenerator>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = llvm::raw_ostream; U = const unsigned int&]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/LangOptions.h:1194:45:   required from here
/usr/include/c++/8/type_traits:2002:38: error: ‘const unsigned int’ is not an enumeration type
/usr/include/c++/8/type_traits: In instantiation of ‘struct std::underlying_type<const char [24]>’:
/usr/include/c++/8/type_traits:2299:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const char [24]]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_UniformRandomNumberGenerator>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = llvm::raw_ostream; U = const char (&)[24]]’
Step 7 (build cmake config) failure: build cmake config (failure)
...
[4113/7793] Building CXX object tools/clang/lib/APINotes/CMakeFiles/obj.clangAPINotes.dir/APINotesTypes.cpp.o
[4114/7793] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/ASTSourceDescriptor.cpp.o
[4115/7793] Building CXX object tools/mlir/lib/Tools/mlir-translate/CMakeFiles/obj.MLIRTranslateLib.dir/MlirTranslateMain.cpp.o
[4116/7793] Building CXX object tools/mlir/lib/Tools/tblgen-lsp-server/CMakeFiles/TableGenLspServerLib.dir/LSPServer.cpp.o
[4117/7793] Building CXX object tools/mlir/examples/minimal-opt/CMakeFiles/mlir-cat.dir/mlir-cat.cpp.o
[4118/7793] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/CodeGenOptions.cpp.o
[4119/7793] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/OperatorPrecedence.cpp.o
[4120/7793] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/FileEntry.cpp.o
[4121/7793] Building CXX object tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/MakeSupport.cpp.o
[4122/7793] Building CXX object tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/DependencyDirectivesScanner.cpp.o
FAILED: tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/DependencyDirectivesScanner.cpp.o 
ccache /usr/bin/c++ -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/build/tools/clang/lib/Lex -I/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/lib/Lex -I/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include -I/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/build/tools/clang/include -I/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/build/include -I/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -Wno-misleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/DependencyDirectivesScanner.cpp.o -MF tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/DependencyDirectivesScanner.cpp.o.d -o tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/DependencyDirectivesScanner.cpp.o -c /home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/lib/Lex/DependencyDirectivesScanner.cpp
In file included from /home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/llvm/include/llvm/ADT/ADL.h:12,
                 from /home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/llvm/include/llvm/ADT/Hashing.h:47,
                 from /home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/CustomizableOptional.h:12,
                 from /home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/FileEntry.h:17,
                 from /home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/SourceLocation.h:17,
                 from /home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Lex/DependencyDirectivesScanner.h:20,
                 from /home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/lib/Lex/DependencyDirectivesScanner.cpp:17:
/usr/include/c++/8/type_traits: In instantiation of ‘struct std::underlying_type<const clang::SourceRange>’:
/usr/include/c++/8/type_traits:2299:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const clang::SourceRange]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_UniformRandomNumberGenerator>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = clang::StreamingDiagnostic; U = const clang::SourceRange&]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/Diagnostic.h:1490:12:   required from here
/usr/include/c++/8/type_traits:2002:38: error: ‘const clang::SourceRange’ is not an enumeration type
       typedef __underlying_type(_Tp) type;
                                      ^~~~
/usr/include/c++/8/type_traits: In instantiation of ‘struct std::underlying_type<const clang::CharSourceRange>’:
/usr/include/c++/8/type_traits:2299:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const clang::CharSourceRange]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_UniformRandomNumberGenerator>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = clang::StreamingDiagnostic; U = const clang::CharSourceRange&]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/Diagnostic.h:1498:12:   required from here
/usr/include/c++/8/type_traits:2002:38: error: ‘const clang::CharSourceRange’ is not an enumeration type
/usr/include/c++/8/type_traits: In instantiation of ‘struct std::underlying_type<const clang::FixItHint>’:
/usr/include/c++/8/type_traits:2299:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const clang::FixItHint]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_UniformRandomNumberGenerator>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = clang::StreamingDiagnostic; U = const clang::FixItHint&]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/Diagnostic.h:1505:12:   required from here
/usr/include/c++/8/type_traits:2002:38: error: ‘const clang::FixItHint’ is not an enumeration type
/usr/include/c++/8/type_traits: In instantiation of ‘struct std::underlying_type<const char [18]>’:
/usr/include/c++/8/type_traits:2299:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const char [18]]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_UniformRandomNumberGenerator>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = llvm::raw_fd_ostream; U = const char (&)[18]]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/LangOptions.h:1194:21:   required from here
/usr/include/c++/8/type_traits:2002:38: error: ‘const char [18]’ is not an enumeration type
/usr/include/c++/8/type_traits: In instantiation of ‘struct std::underlying_type<const unsigned int>’:
/usr/include/c++/8/type_traits:2299:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const unsigned int]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_UniformRandomNumberGenerator>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = llvm::raw_ostream; U = const unsigned int&]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/LangOptions.h:1194:45:   required from here
/usr/include/c++/8/type_traits:2002:38: error: ‘const unsigned int’ is not an enumeration type
/usr/include/c++/8/type_traits: In instantiation of ‘struct std::underlying_type<const char [24]>’:
/usr/include/c++/8/type_traits:2299:66:   required by substitution of ‘template<class _Tp> using underlying_type_t = typename std::underlying_type::type [with _Tp = const char [24]]’
/home/botworker/bbot/amdgpu-offload-rhel-8-cmake-build-only/llvm-project/clang/include/clang/Basic/Diagnostic.h:1441:9:   required by substitution of ‘template<class T, class U> std::enable_if_t<(is_same_v<typename std::remove_const<_Tp>::type, clang::StreamingDiagnostic> && is_scoped_enum_v<typename std::remove_reference<_UniformRandomNumberGenerator>::type>), const clang::StreamingDiagnostic&> clang::operator<<(const T&, U&&) [with T = llvm::raw_ostream; U = const char (&)[24]]’

@erichkeane
Copy link
Collaborator

Also, that build error is problematic and seems correct. The default argument of is_scoped_enum_v is depending on underlying_type_t which is invalid for non-enums? Note that templates don't shortcut with instantiation, so you probably have to 'hide' this somewhere as well.

Endilll added a commit to Endilll/llvm-project that referenced this pull request May 1, 2025
...in old compilers where `std::underlying_type` is not SFINAE-friendly. Fixes buildbot failure https://lab.llvm.org/buildbot/#/builders/134/builds/17904 caused by llvm#138089
@llvm-ci
Copy link
Collaborator

llvm-ci commented May 1, 2025

LLVM Buildbot has detected a new failure on builder ppc64le-flang-rhel-clang running on ppc64le-flang-rhel-test while building clang,llvm at step 5 "build-unified-tree".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/157/builds/26795

Here is the relevant piece of the build log for the reference
Step 5 (build-unified-tree) failure: build (failure)
...
75.835 [2192/1154/3456] Building TestPatterns.inc...
75.844 [2191/1154/3457] Building CXX object tools/mlir/lib/ExecutionEngine/CMakeFiles/mlir_float16_utils.dir/Float16bits.cpp.o
75.857 [2190/1154/3458] Building CXX object tools/mlir/lib/ExecutionEngine/SparseTensor/CMakeFiles/MLIRSparseTensorRuntime.dir/File.cpp.o
75.880 [2189/1154/3459] Building CXX object tools/mlir/lib/ExecutionEngine/SparseTensor/CMakeFiles/MLIRSparseTensorRuntime.dir/MapRef.cpp.o
75.914 [2188/1154/3460] Building CXX object tools/mlir/lib/ExecutionEngine/SparseTensor/CMakeFiles/MLIRSparseTensorRuntime.dir/Storage.cpp.o
75.934 [2187/1154/3461] Building CXX object tools/mlir/lib/ExecutionEngine/CMakeFiles/mlir_c_runner_utils.dir/CRunnerUtils.cpp.o
75.955 [2186/1154/3462] Building CXX object lib/ExecutionEngine/Orc/CMakeFiles/LLVMOrcJIT.dir/LazyObjectLinkingLayer.cpp.o
75.990 [2185/1154/3463] Building CXX object lib/ExecutionEngine/Orc/CMakeFiles/LLVMOrcJIT.dir/Layer.cpp.o
76.004 [2184/1154/3464] Building CXX object tools/llvm-size/CMakeFiles/llvm-size.dir/llvm-size.cpp.o
76.014 [2183/1154/3465] Building CXX object tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/PPCallbacks.cpp.o
FAILED: tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/PPCallbacks.cpp.o 
ccache /home/buildbots/llvm-external-buildbots/clang.19.1.7/bin/clang++ -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/tools/clang/lib/Lex -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/clang/lib/Lex -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/clang/include -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/tools/clang/include -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/include -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/PPCallbacks.cpp.o -MF tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/PPCallbacks.cpp.o.d -o tools/clang/lib/Lex/CMakeFiles/obj.clangLex.dir/PPCallbacks.cpp.o -c /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/clang/lib/Lex/PPCallbacks.cpp
In file included from /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/clang/lib/Lex/PPCallbacks.cpp:9:
In file included from /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/clang/include/clang/Lex/PPCallbacks.h:17:
In file included from /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/clang/include/clang/Basic/DiagnosticIDs.h:18:
In file included from /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/clang/include/clang/Basic/LLVM.h:21:
In file included from /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/include/llvm/Support/Casting.h:18:
In file included from /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/include/llvm/Support/type_traits.h:17:
/usr/lib/gcc/ppc64le-redhat-linux/8/../../../../include/c++/8/type_traits:2002:15: error: only enumeration types have underlying types
 2002 |       typedef __underlying_type(_Tp) type;
      |               ^
/usr/lib/gcc/ppc64le-redhat-linux/8/../../../../include/c++/8/type_traits:2299:5: note: in instantiation of template class 'std::underlying_type<const clang::SourceRange>' requested here
 2299 |     using underlying_type_t = typename underlying_type<_Tp>::type;
      |     ^
/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/include/llvm/ADT/STLForwardCompat.h:76:51: note: in instantiation of template type alias 'underlying_type_t' requested here
   76 | template <typename T, typename UnderlyingT = std::underlying_type_t<T>>
      |                                                   ^
/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/clang/include/clang/Basic/Diagnostic.h:1441:15: note: in instantiation of default argument for 'is_scoped_enum_v<std::remove_reference_t<const SourceRange &>>' required here
 1441 |         llvm::is_scoped_enum_v<std::remove_reference_t<U>>,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/clang/include/clang/Basic/Diagnostic.h:1490:8: note: while substituting deduced template arguments into function template 'operator<<' [with T = StreamingDiagnostic, U = const clang::SourceRange &]
 1490 |     DB << *Opt;
      |        ^
In file included from /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/clang/lib/Lex/PPCallbacks.cpp:9:
In file included from /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/clang/include/clang/Lex/PPCallbacks.h:17:
In file included from /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/clang/include/clang/Basic/DiagnosticIDs.h:18:
In file included from /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/clang/include/clang/Basic/LLVM.h:21:
In file included from /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/include/llvm/Support/Casting.h:18:
In file included from /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/include/llvm/Support/type_traits.h:17:
/usr/lib/gcc/ppc64le-redhat-linux/8/../../../../include/c++/8/type_traits:2002:15: error: only enumeration types have underlying types
 2002 |       typedef __underlying_type(_Tp) type;
      |               ^
/usr/lib/gcc/ppc64le-redhat-linux/8/../../../../include/c++/8/type_traits:2299:5: note: in instantiation of template class 'std::underlying_type<const clang::CharSourceRange>' requested here
 2299 |     using underlying_type_t = typename underlying_type<_Tp>::type;
      |     ^
/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/include/llvm/ADT/STLForwardCompat.h:76:51: note: in instantiation of template type alias 'underlying_type_t' requested here
   76 | template <typename T, typename UnderlyingT = std::underlying_type_t<T>>
      |                                                   ^
/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/clang/include/clang/Basic/Diagnostic.h:1441:15: note: in instantiation of default argument for 'is_scoped_enum_v<std::remove_reference_t<const CharSourceRange &>>' required here

@Endilll Endilll deleted the scoped-enums-in-diags branch May 1, 2025 14:10
Endilll added a commit that referenced this pull request May 1, 2025
Endilll added a commit that referenced this pull request May 1, 2025
`std::underlying_type` is not SFINAE-friendly in Clang and GCC before 9,
and it's too much of a hassle to make it work. Instead, I'm inlining the
implementation in the only place it's needed. Fixes buildbot failure
https://lab.llvm.org/buildbot/#/builders/134/builds/17904 caused by
#138089. Demo: https://godbolt.org/z/9qo3csP98
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
This patch adds templated `operator<<` for diagnostics that pass scoped
enums, saving people from `llvm::to_underlying()` clutter on the side of
emitting the diagnostic. This eliminates 80 out of 220 usages of
`llvm::to_underlying()` in Clang.

I also backported `std::is_scoped_enum_v` from C++23.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
`std::underlying_type` is not SFINAE-friendly in Clang and GCC before 9,
and it's too much of a hassle to make it work. Instead, I'm inlining the
implementation in the only place it's needed. Fixes buildbot failure
https://lab.llvm.org/buildbot/#/builders/134/builds/17904 caused by
llvm#138089. Demo: https://godbolt.org/z/9qo3csP98
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
This patch adds templated `operator<<` for diagnostics that pass scoped
enums, saving people from `llvm::to_underlying()` clutter on the side of
emitting the diagnostic. This eliminates 80 out of 220 usages of
`llvm::to_underlying()` in Clang.

I also backported `std::is_scoped_enum_v` from C++23.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
`std::underlying_type` is not SFINAE-friendly in Clang and GCC before 9,
and it's too much of a hassle to make it work. Instead, I'm inlining the
implementation in the only place it's needed. Fixes buildbot failure
https://lab.llvm.org/buildbot/#/builders/134/builds/17904 caused by
llvm#138089. Demo: https://godbolt.org/z/9qo3csP98
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
This patch adds templated `operator<<` for diagnostics that pass scoped
enums, saving people from `llvm::to_underlying()` clutter on the side of
emitting the diagnostic. This eliminates 80 out of 220 usages of
`llvm::to_underlying()` in Clang.

I also backported `std::is_scoped_enum_v` from C++23.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
`std::underlying_type` is not SFINAE-friendly in Clang and GCC before 9,
and it's too much of a hassle to make it work. Instead, I'm inlining the
implementation in the only place it's needed. Fixes buildbot failure
https://lab.llvm.org/buildbot/#/builders/134/builds/17904 caused by
llvm#138089. Demo: https://godbolt.org/z/9qo3csP98
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
This patch adds templated `operator<<` for diagnostics that pass scoped
enums, saving people from `llvm::to_underlying()` clutter on the side of
emitting the diagnostic. This eliminates 80 out of 220 usages of
`llvm::to_underlying()` in Clang.

I also backported `std::is_scoped_enum_v` from C++23.
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
`std::underlying_type` is not SFINAE-friendly in Clang and GCC before 9,
and it's too much of a hassle to make it work. Instead, I'm inlining the
implementation in the only place it's needed. Fixes buildbot failure
https://lab.llvm.org/buildbot/#/builders/134/builds/17904 caused by
llvm#138089. Demo: https://godbolt.org/z/9qo3csP98
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request May 9, 2025
This patch adds templated `operator<<` for diagnostics that pass scoped
enums, saving people from `llvm::to_underlying()` clutter on the side of
emitting the diagnostic. This eliminates 80 out of 220 usages of
`llvm::to_underlying()` in Clang.

I also backported `std::is_scoped_enum_v` from C++23.
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request May 9, 2025
`std::underlying_type` is not SFINAE-friendly in Clang and GCC before 9,
and it's too much of a hassle to make it work. Instead, I'm inlining the
implementation in the only place it's needed. Fixes buildbot failure
https://lab.llvm.org/buildbot/#/builders/134/builds/17904 caused by
llvm#138089. Demo: https://godbolt.org/z/9qo3csP98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category code-quality llvm:adt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants